/**
 * 专家介绍管理初始化
 */
var ExpertInfo = {
    id: "ExpertInfoTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
ExpertInfo.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '姓名', field: 'name', align: 'center', valign: 'middle', sortable: true},
        {title: '职称', field: 'rank', align: 'center', valign: 'middle', sortable: true},
        {title: '发布者', field: 'createrName', align: 'center', valign: 'middle', sortable: true},
        {title: '排序', field: 'pri', align: 'center', valign: 'middle', sortable: true},
        {title: '创建时间', field: 'created_time', align: 'center', valign: 'middle', sortable: true}
    ];
};

/**
 * 检查是否选中
 */
ExpertInfo.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        ExpertInfo.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加专家介绍
 */
ExpertInfo.openAddExpertInfo = function () {
    var index = layer.open({
        type: 2,
        title: '添加专家介绍',
        area: ['800px', '666px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/hp/expert/expertInfo_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看专家介绍详情
 */
ExpertInfo.openExpertInfoDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '专家介绍详情',
            area: ['800px', '666px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/hp/expert/expertInfo_update/' + ExpertInfo.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除专家介绍
 */
ExpertInfo.delete = function () {
    if (this.check()) {

        var operation = function(){
            var ajax = new $ax(Feng.ctxPath + "/hp/expert/delete", function (data) {
                Feng.success("删除成功!");
                ExpertInfo.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id", ExpertInfo.seItem.id);
            ajax.start();
        };

        Feng.confirm("是否删除专家介绍 " + ExpertInfo.seItem.name + "?", operation);
    }
};

/**
 * 点击分配科室
 * @param
 */
ExpertInfo.departmentAssign = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '分配科室',
            area: ['300px', '500px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/hp/expert/department_assign/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};


/**
 * 查询专家介绍列表
 */
ExpertInfo.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    ExpertInfo.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = ExpertInfo.initColumn();
    var table = new BSTable(ExpertInfo.id, "/hp/expert/list", defaultColunms);
    table.setPaginationType("client");
    ExpertInfo.table = table.init();
});
